package com.hkjtgc.pcr_app.util

import android.content.Context
import android.content.SharedPreferences

class SharedPreferencesUtils private constructor(context: Context) {

    init {
        sharedPreferences = context.getSharedPreferences(mTag, Context.MODE_PRIVATE)
        editor = sharedPreferences.edit()
    }

    fun putSP(key: String, value: String) {
        editor.putString(key, value)
        editor.commit()
    }

    fun getSP(key: String): String {
        return sharedPreferences.getString(key, "") ?: ""
    }

    fun removeSP(key: String) {
        editor.remove(key)
        editor.commit()
    }

    companion object {
        const val mTag = "PCR"
        private lateinit var sharedPreferences: SharedPreferences
        private lateinit var editor: SharedPreferences.Editor
        private var spUtils: SharedPreferencesUtils? = null
        fun getSPInstance(context: Context): SharedPreferencesUtils {
            if (spUtils == null) {
                spUtils = SharedPreferencesUtils(context)
            }
            return spUtils!!
        }
    }
}




